package com.yanqu.road.entity.activity.douluodalu.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;


@FieldTypeAnnotation(tableName = "t_c_douluodalu_team")
public class DouLuoDaLuTeamData extends DataObject {

    @FieldTypeAnnotation(select = true, update = true, desc = "活动ID")
    private int activityId;
    @FieldTypeAnnotation(update = true, desc = "组id")
    private int groupId;
    @FieldTypeAnnotation(update = true, desc = "队伍ID")
    private int teamId;

    @FieldTypeAnnotation(desc = "队长")
    private long captainId;

    @FieldTypeAnnotation(desc = "队长的区服")
    private long captainServerId;

    @FieldTypeAnnotation(desc = "队伍名称")
    private String name = "";

    @FieldTypeAnnotation(desc = "队伍创建时间")
    private long createTime;

    @FieldTypeAnnotation(desc = "队伍成员")
    private Map<Long, Long> memberList = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "队伍申请列表")
    private Map<Long, Long> applyList = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "是否解散")
    private boolean isDelete;


    //缓存
    private long totalEarn;

    public DouLuoDaLuTeamData() {
    }

    public DouLuoDaLuTeamData(int activityId, int groupId, int teamId) {
        this.activityId = activityId;
        this.groupId = groupId;
        this.teamId = teamId;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }

    public int getTeamId() {
        return teamId;
    }

    public void setTeamId(int teamId) {
        if(this.teamId != teamId) {
            this.teamId = teamId;
            setUpdateOption();
        }
    }

    public long getCaptainId() {
        return captainId;
    }

    public void setCaptainId(long captainId) {
        if(this.captainId != captainId) {
            this.captainId = captainId;
            setUpdateOption();
        }
    }

    public long getCaptainServerId() {
        return captainServerId;
    }

    public void setCaptainServerId(long captainServerId) {
        this.captainServerId = captainServerId;
        setUpdateOption();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(!Objects.equals(this.name, name)) {
            this.name = name;
            setUpdateOption();
        }
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        if(this.createTime != createTime) {
            this.createTime = createTime;
            setUpdateOption();
        }
    }

    public Map<Long, Long> getMemberList() {
        return memberList;
    }

    public void removeMember(long userId){
        if(memberList.remove(userId) != null){
            setUpdateOption();
        }
    }

    public void setMemberList(Map<Long, Long> memberList) {
        this.memberList = memberList;
        setUpdateOption();
    }

    public Map<Long, Long> getApplyList() {
        return applyList;
    }

    public void removeApply(long userId){
        if(applyList.containsKey(userId)){
            applyList.remove(userId);
            setUpdateOption();
        }
    }

    public void addApply(long userId, long time){
        applyList.put(userId, time);
        setUpdateOption();
    }


    public void setApplyList(Map<Long, Long> applyList) {
        this.applyList = applyList;
        setUpdateOption();
    }

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean delete) {
        if(isDelete != delete) {
            isDelete = delete;
            setUpdateOption();
        }
    }

    //缓存
    public long getTotalEarn() {
        return totalEarn;
    }

    public void setTotalEarn(long totalEarn) {
        this.totalEarn = totalEarn;
    }
}
